package com.twu.biblioteca.impl;

import com.twu.biblioteca.entity.User;

import javax.servlet.http.HttpServlet;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Login extends HttpServlet {
    User user = new User();

    public List<String> getUserInput() {
        Scanner sc = new Scanner(System.in);
        System.out.println(">> Please enter your username (such as '111-1111'):");
        String inputtedUsername = sc.nextLine();
        System.out.println(">> Please enter your password (such as '123'):");
        String inputtedPassword = sc.nextLine();
        List<String> userInput = new ArrayList<String>();
        userInput.add(inputtedUsername);
        userInput.add(inputtedPassword);
        return userInput;
    }

    public boolean confirmUserInfo(String mayUsername, String mayPassword, List<User> userList) {
        boolean flag = false;
        for(int i = 0; i < userList.size(); i++) {
            user = new User();
            user = userList.get(i);
            if (mayUsername.equals(user.getUsername()) && mayPassword.equals(user.getPassword()))
            {
                flag = true;
                System.out.println(">> Login succeeded!\n");
                break;
            }
            else
                continue;
        }
        return flag;
    }
}
